﻿@{
    ViewBag.Title = "NoticeDetail";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@model Agro.Models.T_Notice
@section head
{
    <script type="text/javascript" src="/Content/ckeditor/ckeditor.js"></script>
    <script type="text/javascript"
     src="@Url.Content("~/Scripts/jquery.uploadify-3.1.js")"  ></script>
    <link href="@Url.Content("~/Content/uploadify/uploadify.css")"     rel="stylesheet" type="text/css" />
    <style type="text/css">
        .uploadify-button
        {
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify:hover .uploadify-button
        {
            background-color: transparent;
        }
        .uploadbtn
        {
            background: url(/content/upload.gif);
            width: 90px;
            height: 30px;
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify-queue
        {
            position: absolute;
            left: 10px;
            top: 5px;
            width: 500px;
        }
        .b-col
        {
            width: 500px;
        }
        .col-input
        {
            width: 300px;
        }
        #File_Title
        {
            width: 300px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var type = '@ViewBag.NoticeType';
        var formid = "";
        $(document).ready(function () {
            if (type == "add")//如果是新发消息，显示附件上传按钮，否则显示附件下载链接
            {
                initUpload();
                $("#downloadfile").css('display', 'none');
                $("#btnImport").css('margin-top', '10px');
            }
            else {
                $("#btnImport").css('display', 'none');
                $("#downloadfile").attr("href", "javascript:download('" + $("#Notice_ID").val() + "')");
                $("#downloadfile").html($("#Notice_AttachmentName").val() + " " + $("#Notice_AttachmentSize").val() + "");
                $("#t1").css('height', '510px');
            }
            CKEDITOR.replace('Notice_Content', { height: 310 });

        });

        function download(id) {
            $("#frmDownFile").attr("src", '/SystemManage/Notice/DownLoadFile?id=' + id);
            //            window.location.href = '/FileManage/File/DownLoadFile?id=' + id;

        }

        function Save(t) {
            formid = t;
            CKEDITOR.instances['Notice_Content'].updateElement();
            var title = $("#Notice_Title").val();
            if (title == "" || title == null) {
                parent.asyncbox.tips('通知标题不能为空!', 'error');
                return;
            }
            var title = $("#Notice_Content").val();
            if (title == "" || title == null) {
                parent.asyncbox.tips('通知内容不能为空!', 'error');
                return;
            }


            //开始保存
            parent.$.cover(true);
            showparentloading();


            //此处判断有无需要上传的文件
            var fileNum = $("#btnImport-queue .uploadify-queue-item").length;
            //如果有需要上传的文件，调用上传的同时，保存页面
            if (fileNum > 0) {
                $('#btnImport').uploadify('upload');
            }
            else {
                //开始保存
                $.funSaveForm("/SystemManage/Notice/NoticeSave", "formDetail", function (d) {
                    hideparentloading();
                    parent.$.cover(false);
                    if (d == undefined || d == "") {
                        parent.asyncbox.tips('发送失败!', 'error');
                        return;
                    }
                    else {
                        parent.asyncbox.tips('发送成功!', 'success');
                        MainFrame().$(MainFrame().gridId).trigger("reloadGrid");
                        parent.$.close(t.id);
                        return;
                    }
                });

            }
        }

        function initUpload() {
            $("#btnImport").uploadify({
                'formData': { 'ASPSESSID': '@(Session.SessionID)', 'AUTHID': '@ViewBag.auth', GUID: '@ViewBag.GUID' },
                'multi': false,
                'auto': false, //设为true自动上传，false需要触发事件上传
                'swf': '/Content/uploadify/uploadify.swf',
                'uploader': '/SystemManage/Notice/NoticeSave',
                'width': 90,
                'fileTypeExts': '*.*',
                'height': 22,
                'fileSizeLimit': '10240KB', //设置上传文件的大小10M
                'queueSizeLimit': 1,
                'buttonImage': '/Content/import.gif',
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    parent.asyncbox.alert('文件上传失败:' + errorString, '提示');
                    parent.$.cover(false);
                    hideparentloading();
                },
                'onUploadStart': function (file) {//开始上传事件
                    showparentloading();
                    parent.$.cover(true);
                    //将form的值加入到formdata中， 这样在controller中，只需要一个方法，即可处理文件上传和消息内容保存
                    mapData = $("#formDetail").serializeJson();
                    $('#btnImport').uploadify('settings', 'formData', mapData);
                },

                'onUploadSuccess': function (file, data, response) {
                    parent.$.cover(false);
                    hideparentloading();
                    var d = $.parseJSON(data);
                    if (d.Data == undefined || d.Data == "") {
                        parent.asyncbox.alert('发送失败!', '提示');

                    }
                    else {
                        parent.asyncbox.tips('发送成功!', 'success');
                        MainFrame().$(MainFrame().gridId).trigger("reloadGrid");
                        $('#btnImport').uploadify('destroy');
                        //
                    }
                },
                'onDestroy': function () {
                    //关闭当前对话框
                    parent.$.close(formid.id);
                }

            });
        }
    </script>
}
<!--主窗体，页面都需要的div-->
<div class="ui-layout-center" style="overflow: hidden;">
    @using (Html.BeginForm("", "", FormMethod.Post, new Dictionary<string, object> { { "id", "formDetail" } }))
    {
        @Html.HiddenFor(m => m.Notice_ID)
        @Html.HiddenFor(m => m.Notice_CreateUser)
        @Html.HiddenFor(m => m.Notice_CreateDate)
        @Html.HiddenFor(m => m.Notice_AttachmentName)
        @Html.HiddenFor(m => m.Notice_AttachmentSize)
        <table class="ui-widget-content" id="t1" style="width: 100%; height: 400px;">
            <tr>
                <td valign="top">
                    <table id="t2">
                        <tr>
                            <td align="right">
                                <font color="red">*</font>通知标题：
                            </td>
                            <td>
                                @Html.TextBoxFor(m => m.Notice_Title, new { style = "width:530px;" })
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <font color="red">*</font>通知内容：
                            </td>
                            <td>
                                @Html.TextAreaFor(m => m.Notice_Content, new { style = "width:300px;height: 150px;" })
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                附件：
                            </td>
                            <td style="position: relative; display: block;">
                                <input type="file" name="btnImport" id="btnImport" />
                                <a id="downloadfile"></a>
                            </td>
                        </tr>
                        <tr><td></td><td></td></tr>
                    </table>
                </td>
            </tr>
        </table>
    }
</div>
<iframe id='frmDownFile' frameborder='0' width='0' height='0' marginheight='0' marginwidth='0'
    scrolling="auto" style="margin: 0px; margin-bottom: -2px;"></iframe>
